/* eslint-disable no-debugger */
import { Spin } from 'antd';
import React from 'react';

/** 懒加载 */
export const lazy = (factory: () => Promise<any>, load?) => props => {
    const [Ct, setCt] = React.useState<any>();
    React.useEffect(() => {
        (async () => {
            const myC = await factory();
            setCt(myC);
        })();
    }, []);

    return (Ct && Ct.default)
        ? <Ct.default {...props} />
        : load || <div style={{ height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center' }} ><Spin /></div>;
};